import _ from 'lodash';
require('./../../libs/pinyinUtil');

export default function (str, mode) {
    if (!str) {
        return '';
    }
    const pinyinUtil = window.pinyinUtil;
    let pys = pinyinUtil.getPinyin(str, ' ', false).split(' ');
    pys = _.filter(pys, i => i !== null && 1 !== '');
    switch (mode) {
    case 1:
        break;
    case 2:
        pys = pys.map(i => i[0]).join('');
        break;
    default:
        const firstChars = pys.map(i => i[0]);
        if (!_.isEqual(pys, firstChars))pys = _.concat(firstChars, ['|'], pys);
        break;
    }
    return pys.join('');
}
